﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using CrystalDecisions.CrystalReports.Engine;
using Wpf2.Models;

namespace Wpf2.Views
{
    /// <summary>
    /// Interaction logic for CrystalReportInventoryViewer.xaml
    /// </summary>
    public partial class CrystalReportInventoryViewer 
    {
        public CrystalReportInventoryViewer(IEnumerable<Products> products, IDictionary<string,string> param)
        {
            InitializeComponent();
            try
            {
              
                var path = Environment.CurrentDirectory;
                var report = new ReportDocument();
                var link = path.Insert(path.Length, "\\CrystalReport\\CrystalReportInventory.rpt");
               
                report.Load(link);
                report.SetDataSource(products.ToList());
                report.SetParameterValue("StoreName", param["StoreName"]);
                report.SetParameterValue("Address", param["Address"]);
                report.SetParameterValue("Phone", param["Phone"]);
                report.SetParameterValue("Mobile", param["Mobile"]);
                report.SetParameterValue("ProductId", param["ProductId"]);
                report.SetParameterValue("ProductName", param["ProductName"]);
                report.SetParameterValue("ProductDescription", param["ProductDescription"]);
                report.SetParameterValue("ProductQuantity", param["ProductQuantity"]);
                report.SetParameterValue("ProductCostPrice", param["ProductCostPrice"]);
                report.SetParameterValue("ProductCellPrice", param["ProductCellPrice"]);
                report.SetParameterValue("ProductUnit", param["ProductUnit"]);
                report.SetParameterValue("ProductCatalog", param["ProductCatalog"]);
              
                CRViewer.ViewerCore.ReportSource = report;
            }
            catch (Exception e)
            {

                MessageBox.Show(e.Message);
            }
        }
    }
}
